package chapter06

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test17_Extends
 * Package: chapter06
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-06-23
 *          Time: 20:44
 */

object Test17_Extends {
  def main(args: Array[String]): Unit = {
    //1.类型的检测和转换
    val student = new Student17("alice", 18)
    student.study()
    student.sayHi
    //多态的效果
    val person: Person17 = new Student17("bob", 20)
    person.sayHi

    //判断类型的方法
    println("student is Student17: " + student.isInstanceOf[Student17])
    println("student is Person17: " + student.isInstanceOf[Person17])

    println("Person is Person17: " + student.isInstanceOf[Person17])
    println("Person is Student: " + student.isInstanceOf[Student17])
    //子类可以是父类类型 父类不可以是子类类型


    //类型转换
    if (student.isInstanceOf[Student17]) {
      val newStu = person.asInstanceOf[Student17]
      newStu.study()
    }

    println(classOf[Student17])

    //测试枚举对象
    println(WorkDay.MONDAY)

  }

}

//定义一个应用类
object TestApp extends App{
  println("app start")


  type MyString = String
  val a:MyString = "abc"
  println(a)

}

//定义一个枚举类对象
object WorkDay extends Enumeration {
  val MONDAY = Value(1,"Monday")
  val TUESDAY = Value(2,"TuesDay")
}


class Person17(val name: String, val age: Int) {
  def sayHi: Unit = {
    println("hi from person " + name)
  }
}


class Student17(name: String, age: Int) extends Person17(name, age) {
  override def sayHi: Unit = {
    println("hi from student " + name)
  }

  def study(): Unit = {
    println("student")
  }
}
